package com.chainyoung.common.di.module;

import android.app.Application;
import android.content.Context;

import com.chainyoung.common.constant.LibConstant;
import com.chainyoung.common.http.websocket.WsManager;

import java.util.List;
import java.util.concurrent.TimeUnit;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;

@Module
public class WSClientModule {

    private Application mApplication;

    public WSClientModule(Application application) {
        this.mApplication = application;
    }


    @Singleton
    @Provides
    public Application provideApplication() {
        return mApplication;
    }

    /**
     * 提供Websocket 的 OkhttpClient
     */
    @Singleton
    @Provides
    OkHttpClient provideClient() {
        OkHttpClient client = new OkHttpClient().newBuilder().pingInterval(15, TimeUnit.SECONDS)
                .retryOnConnectionFailure(true)
                .build();
        return client;

    }


    /**
     * 提供Websocket 的 OkhttpClient
     */
    @Singleton
    @Provides
    WsManager provideWsManager(OkHttpClient okHttpClient) {
        WsManager wsManager = new WsManager.Builder(mApplication.getApplicationContext())
                .wsUrl(LibConstant.WS_URL)
                .needReconnect(true)
                .client(okHttpClient)
                .build();
        return wsManager;

    }


}
